package com.base.cn.platform.os.service.manage.log;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.common.utils.DateUtils;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.dao.manage.log.OpLogDao;
import com.base.cn.platform.os.entity.manage.log.OpLogEntity;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

/**
 * 文 件 名:OpLogBiz
 * 创 建 人:hackeridear
 * 创建日期:2018-12-05
 * 描   述:OpLogBiz
 * 修 改 人:
 * 修改日期:
 * 版 本 号:v 1.0.0
 */
@Service
//@EnableAsync
public class OpLogBiz extends BaseBiz<OpLogEntity, OpLogDao> {

//    @Async
    public void addOpLog(OpLogEntity opLogEntity){
        this.save(opLogEntity);
    }

    /**
     * 分页查询 操作日志
     * @param condition
     * @param page
     * @return
     */
    public PageInfo<OpLogEntity> findOpLogListPage(OpLogEntity condition, Pagination page){
        return  this.findPage(whereSql(condition),page,null);
    }

    private String whereSql(OpLogEntity condition){
        StringBuilder sql = new StringBuilder(" 1= 1");
        if(ObjectUtils.isNotEmpty(condition.getStartCreateTime())){
            sql .append(" and createTime >= '").append( DateUtils.format(condition.getStartCreateTime(),"yyyy-MM-dd HH:mm:ss")).append("'");

        }
        if(ObjectUtils.isNotEmpty(condition.getEndCreateTime())){
            sql .append(" and createTime <= '").append( DateUtils.format(condition.getEndCreateTime(),"yyyy-MM-dd HH:mm:ss")).append("'");
        }
        sql .append( " ORDER BY createTime desc");
        return sql.toString();
    }

}
